package commands;

import nanoxml.XMLElement;
import utils.ITransmittable;

/**
 * This command represents a request for the DB to update a
 * game's result.
 */
public class CommandGameResult implements ITransmittable {

	private final static String ATTR_WINNER_NAME = "winnerName";
	private final static String ATTR_LOSER_NAME = "loserName";
	
	private String winner = null; 
	private String loser = null;
	
	public CommandGameResult (String winnerName, String loserName) {
		this.winner = winnerName;
		this.loser = loserName;
	}
	public CommandGameResult (XMLElement command) {
		this.winner = (String) command.getAttribute(ATTR_WINNER_NAME);
		this.loser = (String) command.getAttribute(ATTR_LOSER_NAME);		
	}
	
	@Override
	public XMLElement toXML() {
		XMLElement message = new XMLElement();
		message.setName(Commands.GAME_RESULT);
		message.setAttribute(ATTR_WINNER_NAME, winner);
		message.setAttribute(ATTR_LOSER_NAME, loser);		
		return message;
	}
	
	public String getWinnerName()
	{
		return winner;
	}
	
	public String getLoserName()
	{
		return loser;
	}
	
}
